import Vue from 'vue'
import Vuex from 'vuex'
// import state from './state'
// import actions from './actions'
// import mutations from './mutations'

Vue.use(Vuex);

export default new Vuex.Store({
	// strict:true,
	state:{
		//choose:0-默认，1-循环，2-随机
		lines:[{id:'1',choose:0},{id:'2',choose:0},{id:'3',choose:0},
				{id:'4',choose:0},{id:'5',choose:0},{id:'6',choose:0}],
		count:7,
		show_key:false,
		show_type:false
	},
	actions:{
		addBar(ctx,add_num){
			ctx.commit('addBar',add_num);
		},
		delBar(ctx,del_num){
			ctx.commit('delBar',del_num);
		},
		minus(ctx,id){
			ctx.commit('minus',id);
		},
		setChoose(ctx,{index,choose}){
			ctx.commit('setChoose',{index,choose})
		}
	},
	mutations:{
		addBar(state,add_num){
			for (let i=0;i<add_num;i++){
				state.lines.push({id:''+state.count,choose:0});
				state.count++;
			}
		},
		delBar(state,del_num){
			state.lines.splice(state.lines.length-del_num,del_num);
		},
		minus(state,id){
			let lines = state.lines;
			for(let i=0;i<lines.length;i++){
				if(lines[i].id === id)
					state.lines.splice(i,1);
			}
		},
		setChoose(state,{index,choose}){
			state.lines[index].choose = choose;
		}
	}
})
